package com.toman.templateActivity.controler;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.toman.Enum.NetworkEnum;
import com.toman.Enum.ViewTypeEnum;
import com.toman.R;
import com.toman.Util.DefaultAcitonCallback;
import com.toman.Util.DensityUtil;
import com.toman.Util.DialogUtils;
import com.toman.Util.ViewUtil;
import com.toman.bean.ItemListBean;
import com.toman.bean.TemplateInfBean;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;

/**
 * Created by 邹苏隆 on 2019/1/8.
 * description：
 */
@Data
public class TempFoldAdapter implements TempInterface{
private String name;
private TempInterface foldAdapter;
boolean isMarginTop=false;
    boolean edit = false;

    private List<TemplateInfBean> list;

    public TempFoldAdapter(List<TemplateInfBean> list ,String name) {
        this.list=list;
        this.name = name;
    }
    public TempFoldAdapter(List<TemplateInfBean> list ,String name,boolean isMarginTop) {
        this.list=list;
        this.name = name;
        this.isMarginTop=isMarginTop;
    }
    public TempFoldAdapter(List<TemplateInfBean> list ,String name,boolean isMarginTop,boolean edit) {
        this.list=list;
        this.name = name;
        this.isMarginTop=isMarginTop;
        this.edit=edit;
    }

    public void setList(List<TemplateInfBean> list) {
        this.list = list;
    }

    public View createView(Context context) {
        RelativeLayout.LayoutParams rlParams0 =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, DensityUtil.dip2px(context, 48)
                );

        RelativeLayout.LayoutParams rlParams =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams rlParams2 =
                new RelativeLayout.LayoutParams(
                        DensityUtil.dip2px(context, 215),
                        DensityUtil.dip2px(context, 34));


        RelativeLayout relativeLayout = new RelativeLayout(new ContextThemeWrapper(context, R.style.rl_edit_inf));
        TextView textView = new TextView(new ContextThemeWrapper(context, R.style.tv_edit_left));
        textView.setText(name);

        textView.setId(R.id.tv_code_title);
        rlParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        rlParams.addRule(RelativeLayout.CENTER_VERTICAL);
        textView.setPadding(DensityUtil.dip2px(context, 14), 0, 0, 0);
        relativeLayout.addView(textView, rlParams);

//        TextView editText =new TextView(context);
        ImageView imageView = new ImageView(context);
        RelativeLayout.LayoutParams imageParams =
                new RelativeLayout.LayoutParams(
                        DensityUtil.dip2px(context, 42),
                        DensityUtil.dip2px(context, 42));
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        imageParams.addRule(RelativeLayout.CENTER_VERTICAL);
        imageView.setPadding( DensityUtil.dip2px(context, 14),DensityUtil.dip2px(context, 14),DensityUtil.dip2px(context, 14),DensityUtil.dip2px(context, 14));
        imageView.setImageResource(R.mipmap.upward);
//imageParams.setMargins(0,0,   DensityUtil.dip2px(context, 14),0);
        rlParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        rlParams2.addRule(RelativeLayout.CENTER_VERTICAL);
        LinearLayout llParent = new LinearLayout(context);
llParent.setOrientation(LinearLayout.VERTICAL);
        LinearLayout llChild = new LinearLayout(context);

        relativeLayout.addView(imageView, imageParams);
        if (isMarginTop) {
            rlParams0.setMargins(0, DensityUtil.dip2px(context, 6), 0, 0);
        }
        llParent.addView(relativeLayout,rlParams0);
        llParent.addView(llChild);
        imageView.setOnClickListener(v -> ViewUtil.hide(llChild,imageView));
        llChild.setOrientation(LinearLayout.VERTICAL);
addLine(context,llChild);
         foldAdapter = new TempInfAdapter(list, context, llChild, edit);

return llParent;
    }

    @Override
    public List<TemplateInfBean> getTempBeanList() {
        return this.list;
    }

    private void addLine(Context context,LinearLayout relativeLayout) {

        RelativeLayout.LayoutParams rlParams0 =
                new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 1)
                );

        View line = new View(context);
        line.setBackgroundColor(Color.parseColor("#e6e4e4"));
        rlParams0.setMargins(DensityUtil.dip2px(context, 14), 0, DensityUtil.dip2px(context, 14), 0);
        rlParams0.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        relativeLayout.addView(line, rlParams0);

    }
}
